<?php                                 
  session_start();     
  error_reporting(E_ERROR);
  header('Content-Type:text/html; charset=utf-8');
  define('ROOT',dirname(__FILE__));              
  
  require(ROOT.'/smarty/Smarty.class.php');    
  require(ROOT.'/include/mysql.class.php');     
  require(ROOT.'/include/xml.class.php');      
  require(ROOT.'/include/data.class.php');      
  require(ROOT.'/include/date.class.php');      
  require(ROOT.'/include/log.class.php');
  require(ROOT.'/config_db.php');  
  
  //配置smarty
  $smarty = new Smarty();   
  $smarty->template_dir = ROOT.'/html/';
  $smarty->compile_dir = ROOT.'/cache/';
  $smarty->left_delimiter = '{{';
  $smarty->right_delimiter = '}}';
  
  //配置log
  $log = KLogger::instance(ROOT.'/logs', KLogger::DEBUG); 
  
  //检查数据库是否连接成功
  $db=Mysql::getInstance($mysql_host,$mysql_user,$mysql_pass,$mysql_dbname,$mysql_port);
  
  //记录访问痕迹
  $visitorUser = empty($_SESSION['user']['id']) ? '0' : $_SESSION['user']['id'];
  $visitorIP = $_SERVER['REMOTE_ADDR'];
  $visitorURL = 'http://'.$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
  $visitorTime = DateUtil::get_YY_mm_dd_HH_mm_ss();
  $sql = "insert into talking_visitor(VisitorUser,VisitorIP,VisitorURL,VisitorTime) values ('$visitorUser','$visitorIP','$visitorURL','$visitorTime')";
  $db->execute($sql);     
                          
  //初始化标题、描述、关键字、当前Url
  $xml = new SimpleXMLUtil(ROOT.'/common.xml');
  $webTitle = $xml->getElementValue('Name');
  $webMetaTitle = $xml->getElementValue('MetaTitle');
  $webKeywords = $xml->getElementValue('MetaKeywords');
  $webMetaDescription = $xml->getElementValue('MetaDescription');
  $webMetaOther = $xml->getElementValue('MetaOther');
  $webURL = $xml->getElementValue('URL');
  $webICP = $xml->getElementValue('ICP');
  $smarty->assign('title',$webTitle);       
  $smarty->assign('metaTitle',$webMetaTitle);
  $smarty->assign('metaKeywords',$webKeywords);
  $smarty->assign('metaDescription',$webMetaDescription);
  $smarty->assign('metaOther',$webMetaOther);
  $smarty->assign('url',$webURL);
  $smarty->assign('ICP',$webICP);
  $smarty->assign('visitorURL',$visitorURL);
  
  //判断用户是否登录
  if(isset($_SESSION['user']))
  {
      $smarty->assign('isLogin','y');
      $smarty->assign('userid',$_SESSION['user']['id']);
      $smarty->assign('username',$_SESSION['user']['name']);
  }
                                                                                         
  
  //记录访问次数
  $visitorNum = $xml->getElementValue('VisitNum');
  $visitorNum = intval($visitorNum);
  $xml->setElementValue('VisitNum',$visitorNum+1);
  $xml->save();
?>
